<?php
/***************************************************************************/
/*     SCRIPT NAME    :  view_kegging.php                                  */
/*     CREATED ON     :  15/Mar/2012                                       */
/*     LAST MODIFIED  :  15/Mar/2012                                       */
/*     show all the brews that will be 'bottled' or 'kegged' on the  
       selected  day                                                       */
/***************************************************************************/

include("session.php");
include("../includes/DbManager.php");
include("../includes/Utilities.class.php");
include("../includes/Customer.php");
include("../includes/Orders.php");

$con= new DbManager();
$con->connect();


$customerObj   = new Customer();
$orderObj      = new Orders();


if(!empty($_GET['msg'])){
	$msg=$_GET['msg'];
}
$today=date("Y-m-d");
//Cooking

$sql="SELECT * FROM `order` WHERE  '$today'=CAST(`brew_date` AS DATE) AND `status`!='Cancelled'";
$cooking=$con->fetchAll($sql);
                                                                           
//Kegging
$sql="SELECT * FROM `order` WHERE '$today'=CAST(`pickup_date` AS DATE) OR '$today'=CAST(`bottling_date` AS DATE) AND `status`!='Cancelled'";
$kegging=$con->fetchAll($sql);

include("template/includes/header.php");
include("order_menu.php");



?>
<link type="text/css" rel="stylesheet" href="../calendar/dhtmlgoodies_calendar.css?random=20051112" media="screen"></LINK>
<SCRIPT type="text/javascript" src="../calendar/dhtmlgoodies_calendar.js?random=20060118"></script>
<div id="page-content">
    <!-- Start Page Header -->
    <div id="page-header">
	 <h1>View Cooking & Kegging</h1>
         </div>
    <!-- End Page Header -->
    <!-- Start Grid -->

<form name="orderForm" method="POST" action=""  >
		<div class="grid_4">
		
		<div class="box-header">View Cooking </div>
			<div class="box table">
			<table class="noborder">		
			<TR >
					<TD style="font-size:120%;">Brew date</TD>
                        <TD><input name="brew_date" type="text" id="brew_date" onclick="displayCalendar(document.getElementById('brew_date'),'dd/mm/yyyy',this)" value="<?php  echo date("d/m/Y"); ?>"   > 
                 </TD>
			</TR>

                <tr>		
		          <TD></TD>
				    <TD><input type="button" name="submit_cook" id="submit_cook" value="Submit" class="button medium"></TD>
				</tr>
			</table>
 </div>

</div>
</form>


<form name="id_show_report" id="id_show_cooking_report" method="POST" action=""  >
                                                                 <link media="print" rel="Alternate" href="print.pdf">

		<div class="grid_12">	
		<div class="box-header">Cooking Sheet&nbsp; <span class="fr"><a  target="_blank" href="print_cooking.php?date=<?php echo date("Y-m-d"); ?>" class="over">Print</a></span></div>
        
		<div class="box table">
<table style="font-size:120%;">
			<thead>
			<tr>
                <td>Sl.No</td>
                <td>Customer Name</td>
                <td>Brew </td>
                <td>Order ID </td>
                <td>Date ready </td>
                
                <!--<td>Transfer to cool room </td>-->
				<td>Payment Status </td>
                <td>Note </td>
                <td>Action </td>
				<td></td>
			</tr>
			</thead>
			<tbody>
			<?php if($cooking){ $j=0;
                         for($i=0;$i<count($cooking);$i++) { 
                      $product     =     $orderObj->getProductDetails($cooking[$i]['brew_id']);
                      $customer	   =	$customerObj->getCustomers($cooking[$i]['customer_id']);
            ?>
			<tr>
                <td><?php echo ++$j; ?></td>
                <td align="center" ><a href="customer_details.php?id=<?php echo $cooking[$i]["customer_id"]; ?>"><?php echo $customer[0]["first_name"].' '.$customer[0]["last_name"];?></a></td>
                <td><?php echo $product[0]["beer_name"];?></td>

                <td align="center"><a href="order_details.php?id=<?php echo $cooking[$i]["id"]; ?>"><?php echo $cooking[$i]["order_id"];?></a></td>

                <td><?php echo date("d/m/Y", strtotime($cooking[$i]["brew_date"]." + "."14 days"));?></td>
                <!--<td><?php /*echo date("d/m/Y", strtotime($cooking[$i]["brew_date"]." + "."10 days"));*/?></td>-->

                <td><?php if($cooking[$i]["payment_received"]=="yes"){echo 'Paid';}else {echo 'Not paid';}?></td>
                <td><?php echo $cooking[$i]["note"];?></td>
				<td align="center"><a href="edit_order.php?id=<?php echo $cooking[$i]["id"]; ?>">Edit Order</a></td>
				<td align="center"><input type="checkbox" id="chk1" name="chk1" value="<?php echo $cooking[$i]["id"]; ?>" <?php echo $cooking[$i]["cooking_kegging_status"]?"checked='checked'":""; ?>>
			</tr>			
			</tbody>
        <?php }
}else{ ?>
<tr> <td colspan="8"><div style='display: block;' class='notification info'> <span  class='strong'>No Brews have brew date today !</span>  </div></td>
</tr>
<?php } ?>
			</table>

	</div>
   </div>
  
</form>

		<form name="orderForm" method="POST" action=""  >
		<div class="grid_4">
		
		<div class="box-header">View Kegging</div>
			<div class="box table">
        

			<table class="noborder">		
			<TR >
					<TD style="font-size:120%;" >Pick up date</TD>
                        <TD><input name="pickup_date" type="text" id="pickup_date" onclick="displayCalendar(document.getElementById('pickup_date'),'dd/mm/yyyy',this)" value="<?php  echo date("d/m/Y"); ?>"   > 
                 </TD>
			</TR>

                <tr>		
		          <TD></TD>
				<TD><input type="button" name="submit_kegg" id="submit_kegg" value="Submit" class="button medium"></TD>
				</tr>
			</table>
	
		
		
	
 </div>

</div>
</form>
<form name="id_show_report" id="id_show_kegging_report" method="POST" action=""  >

		<div class="grid_13">	
		<div class="box-header">Kegging Sheet<span class="fr"><a  target="_blank" href="print_kegging.php?date=<?php echo date("Y-m-d"); ?>" class="over">Print</a></div>
		<div class="box table">
        <table style="font-size:120%;">
			<thead>
			<tr>

                <td>Sl.No</td>
                <td>Customer Name</td>
                <td>Brew </td>
                <td>Order ID </td>
                <td>Date ready </td>
                <td>Bottling Date </td>
                <td>Bottling Time</td>
				<td>Payment Status </td>
                <td>Note </td>
                <td>Action </td>
				<td></td>

			</tr>
			</thead>
			<tbody>
			<?php if($kegging){ $j=0;
                         for($i=0;$i<count($kegging);$i++) { 
                      $product     =     $orderObj->getProductDetails($kegging[$i]['brew_id']);
                      $customer		    =	$customerObj->getCustomers($kegging[$i]['customer_id']);
            ?>
			<tr>
                <td ><?php echo ++$j; ?></td>
                <td align="center" ><a href="customer_details.php?id=<?php echo $kegging[$i]["customer_id"]; ?>"><?php echo $customer[0]["first_name"].' '.$customer[0]["last_name"];?></a></td>
                <td><?php echo $product[0]["beer_name"];?></td>
                <td align="center"><a href="order_details.php?id=<?php echo $kegging[$i]["id"]; ?>"><?php echo $kegging[$i]["order_id"];?></a></td>
                <td><?php echo date("d/m/Y", strtotime($kegging[$i]["brew_date"]." + "."14 days")); ?></td>
                <td><?php if($kegging[$i]["bottling_date"]){ echo date("d/m/Y", strtotime($kegging[$i]["bottling_date"]));}else {echo 'Nil';} ;?></td>
                <td><?php $arr=explode(" ",$kegging[$i]['bottling_date']); if($arr[1]){ echo $arr[1];}else {echo 'Nil';} ?></td>
               <td><?php if($kegging[$i]["payment_received"]=="yes"){echo 'Paid';}else {echo 'Not paid';}?></td>
               <td><?php echo $kegging[$i]["note"];?></td>
               <td align="center"><a href="edit_order.php?id=<?php echo $kegging[$i]["id"]; ?>">Edit Order</a></td>
				<td align="center"><input type="checkbox" id="chk1" name="chk1" value="<?php echo $kegging[$i]["id"]; ?>" <?php echo $kegging[$i]["cooking_kegging_status"]?"checked='checked'":""; ?>>
			</tr>			
			</tbody>
        <?php }
}else{ ?>
<tr> <td colspan="10"><div style='display: block;' class='notification info'> <span  class='strong'>No Brews are there for picking up today!</span>  </div></td>
</tr>
<?php } ?>
			</table>

	</div>
   </div>
  
</form>
        <br class="cl" />
        <!-- End Layout Example --> 
        
        <!-- End Grid --> 
      </div>
      <!-- End Page Wrapper --> 
    </div>
    <!-- End Page Content  --> 
  </div>

<?php  include("template/includes/footer.php");?>

<script language="JavaScript">

$(document).ready(function() {

   $("#submit_kegg").click(function(){  //
     
        if($("#pickup_date").val() ) {
               
              $.get("../Ajax/common_ajax.php",{values: $("#pickup_date").val(),process:'view_kegging'}, function(data){		
			$("#id_show_kegging_report").html(data);
		});

        }

   });


   $("#submit_cook").click(function(){  //
     
        if($("#brew_date").val() ) {
               
              $.get("../Ajax/common_ajax.php",{values: $("#brew_date").val(),process:'view_cooking'}, function(data){		
			$("#id_show_cooking_report").html(data);
		});

        }

   });
   
	$(":checkbox").each(function() {
		if($(this).is(':checked'))
                                 {
									$(this).parent().parent().children("td").css("background-color","#98FB98");
                                 }
	});






$(":checkbox").click(function(){
                                 if($(this).is(':checked'))
                                 {
									var e=$(this);
									e.parent().parent().children("td").css("background-color","#EEE8AA");
									
									$.ajax({
										url: "../Ajax/cooking_kegging_status.php",
										data: {id: $(this).val(), value: 1},
										success: function(data){
										if(data == 1) {
											e.parent().parent().children("td").css("background-color","#98FB98");
										}
										else
										{
											e.parent().parent().children("td").css("background-color","white");
										}
									},
									async: true
									});
                                 }
								 else
								 {
									var e=$(this);
									e.parent().parent().children("td").css("background-color","#EEE8AA");
									$.ajax({
										url: "../Ajax/cooking_kegging_status.php",
										data: {id: $(this).val(), value: 0},
										success: function(data){
										if(data == 1) {
											e.parent().parent().children("td").css("background-color","white");
										}
										else
										{
											e.parent().parent().children("td").css("background-color","#98FB98");
										}
									},
									async: true
									});
								 }
                          });


});

</script>

